﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Function
{
    public partial class FunctionForm : Form
    {
        Form Index;
        bool isExit = true;
        bool isRunning = false;

        public FunctionForm()
        {
            InitializeComponent();
        }

        public FunctionForm(Form Index)
        {
            InitializeComponent();
            this.Index = Index;
        }

        private void FunctionForm_Load(object sender, EventArgs e)
        {

        }

        private void FunctionForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (isExit) Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 等待三秒后,把textBox1的内容以SendKeys方式逐字输出到其他地方,注意textBox1的内容包含换行符,输出间隔0.01秒
            if (isRunning) return;
            isRunning = true;
            Task.Run(() => {
                Thread.Sleep(3000);
                for (int i = 0; i < textBox1.Text.Length; i++)
                {
                    SendKeys.SendWait(textBox1.Text[i].ToString());
                    Thread.Sleep(10);
                }
                isRunning = false;
                return;
            });
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Index.Show();
            Index.Location = this.Location;
            isExit = false;
            this.Close();
        }
    }
}
